package com.denlaku.longan.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * redisson配置信息
 *
 * @author tianx
 */
@Configuration
@EnableConfigurationProperties(RedisProperties.class)
@ConditionalOnProperty(prefix = "longan", value = "deployMode", havingValue = "MULTI")
public class RedissonConfig {
    @Bean
    @ConditionalOnProperty(prefix = "redis", value = "address")
    public RedissonClient redissonClient(RedisProperties redisProperties) {
        Config config = new Config();
        config.useSingleServer().setAddress(redisProperties.getAddress()).setPassword(redisProperties.getPassword());
        config.setCodec(new StringCodec());
        return Redisson.create(config);
    }
}
